package my.fra.example;

import my.fra.Fraction;
/**
 * 测试Fraction类的函数
 * @author oyz
 *
 */
public class FraTest {

	public static void test1(){
		System.out.println("--生成对象测试--------------------------------------");
		System.out.println(new Fraction());
		System.out.println(new Fraction(1,2));
		System.out.println(new Fraction(-1,1,1,2,false));
		System.out.println(new Fraction(101232334l,123334444433l));
		
		System.out.println(Fraction.ONE);
		System.out.println(Fraction.TEN);
		System.out.println(Fraction.HALF);
		
	}

	public static void test2(){
		System.out.println("--函数测试--------------------------------------");
		Fraction fraction=new Fraction(-12.3);
		Fraction fraction2=new Fraction(-0.7);
		System.out.println(fraction.toAutoString());
		System.out.println(fraction.opposite().toAutoString());
		System.out.println(fraction.abs().toAutoString());
		System.out.println(fraction.setMixedNumber(true).toAutoString());
		System.out.println(fraction.reciprocal().toAutoString());
		System.out.println(fraction.toDecimalString());
		
		System.out.println(fraction.add(fraction2).toAutoString());
		System.out.println(fraction.add(fraction2.opposite()).toAutoString());
		System.out.println(fraction.subtract(fraction2).toAutoString());
		System.out.println(fraction.subtract(fraction2.opposite()).toAutoString());
		System.out.println(fraction.multiply(Fraction.TEN.opposite()).toAutoString());
		System.out.println(fraction.divide(Fraction.TEN).toAutoString());
	}
	public static void test3(){
		System.out.println("--字符串转换测试--------------------------------------");
		System.out.println(Fraction.parseFraction("-1"));
		System.out.println(Fraction.parseFraction("0.12344000"));
		System.out.println(Fraction.parseFraction(".233"));
		System.out.println(Fraction.parseFraction("-1/2"));
		System.out.println(Fraction.parseFraction("-0.3/0.2"));
		System.out.println(Fraction.parseFraction("(12)"));
		System.out.println(Fraction.parseFraction("(12.3)"));
		System.out.println(Fraction.parseFraction("(1)1/5"));
		System.out.println(Fraction.parseFraction("0"));
	}
    
	public static void test4(){
		System.out.println("--比较函数测试--------------------------------------");
		Fraction fraction1=Fraction.parseFraction("1.22");
		Fraction fraction2=Fraction.parseFraction("1.223");
		Fraction fraction3=Fraction.parseFraction("1.22");
		System.out.println(fraction1.compareTo(fraction3));
		System.out.println(fraction1.compareTo(fraction2));
		System.out.println(fraction1.opposite().compareTo(fraction2));
		System.out.println(fraction1.opposite().compareTo(fraction2.opposite()));
	}
	public static void test5(){
		System.out.println("--异常测试--------------------------------------");
		try {
			System.out.println(Fraction.TEN.divide(Fraction.ZERO));
		}catch(ArithmeticException e){
			System.err.println("异常");
		}
		try {
			System.out.println(new Fraction(0,0));
		}catch(ArithmeticException e){
			System.err.println("异常");
		}
	}
	public static void main(String[] args) {
		test1();
		test2();
		test3();
		test4();
		test5();
	}
}
